#include <stdio.h>

#include "timer_manager.h"

using namespace kingnet ;

class my_timer : public base_timer
{
public:
    explicit my_timer(timer_manager* manager,int id,int expired)
    {
        m_id = id ;
        set_expired(expired) ;
        int ret = manager->add_timer(this) ;
        if(ret!=0) printf("add_timer failed ret:%d\n",ret) ;

        

    }


    void on_timeout(timer_manager* manager)
    {
        printf("timeout id:%d expired:%lld manager curr expired:%lld next_expired:%lld\n",m_id,get_expired(),
            manager->get_curr_expired(),manager->get_next_expired() ) ;
        delete this ;
    }

private:
    int m_id ;
} ;

int main()
{
    int begin = 1000 ;
    timer_manager engine;
    engine.init(begin,3) ;

    my_timer *t = NULL ;
    
    for(int i = 0 ; i < 17 ; ++i)
    {
        t = new my_timer(&engine,i,1000+i) ;
    }

    for(int i = 3 ; i < 7 ; ++i)
    {
        t = new my_timer(&engine,8*i,1000+8*i) ;
        t = new my_timer(&engine,8*i+1,1000+8*i+1) ;
    }
    
    
    for(int i = begin ; i < begin + 200 ; ++i)
    {
        printf("run_until:%d\n",i) ;
        engine.run_until(i) ;
    }
    
    //engine.run_until(2000) ;
    printf("engine curr expired:%lld\n",engine.get_curr_expired()) ;

    return 0 ;

}

//IMPLEMENT_MAIN

